package com.wei.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wei.entity.*;
import com.wei.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李泽伟
 * @since 2022-03-08
 */
@RestController
@RequestMapping
public class HomeController {

    @Autowired
    private GdAccountMapper accountMapper;
    @Autowired
    private GdComplainMapper complainMapper;
    @Autowired
    private GdEquipmentMapper equipmentMapper;
    @Autowired
    private GdFeeMapper feeMapper;
    @Autowired
    private GdHouseholdMapper householdMapper;
    @Autowired
    private GdParkingMapper parkingMapper;
    @Autowired
    private GdPropertyMapper propertyMapper;
    @Autowired
    private GdRepairsMapper repairsMapper;

    @RequestMapping("/getHomeAdminData")
    public String getHomeAdminData(){
        int household,property,account,equipment,parking,complain,repairs,fee;
        //条件构造器
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        //住户数量
        household=householdMapper.selectByMap(map).size();
        //房产数量
        property=propertyMapper.selectByMap(map).size();
        //系统账号数量
        account=accountMapper.selectByMap(map).size();
        //设备数量
        equipment=equipmentMapper.selectByMap(map).size();
        //停车位数量
        parking=parkingMapper.selectByMap(map).size();
        //投诉未处理数量
        QueryWrapper<GdComplain> wrapper1=new QueryWrapper<>();
        wrapper1.eq("complain_situation","未解决").or().eq("complain_situation","处理中");
        complain=complainMapper.selectList(wrapper1).size();
        //报修未处理数量
        QueryWrapper<GdRepairs> wrapper2=new QueryWrapper<>();
        wrapper2.eq("repairs_situation","未进行");
        repairs=repairsMapper.selectList(wrapper2).size();
        //月账单未缴清数量
        QueryWrapper<GdFee> wrapper3=new QueryWrapper<>();
        wrapper3.eq("fee_status","未缴清").or().eq("fee_status","已逾期");
        fee=feeMapper.selectList(wrapper3).size();
        System.out.println(household+"---"+property+"---"+account+"---"+equipment+"---"+parking+"---"+complain+"---"+repairs+"---"+fee);
        return household+"---"+property+"---"+account+"---"+equipment+"---"+parking+"---"+complain+"---"+repairs+"---"+fee;
    }
}

